<%@ page language="java" errorPage="/common/error.jsp" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8" %>
<%@ page isELIgnored="false" %>
<%@ include file="/common/taglibs.jsp"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Pragma" content="no-cache">
<link href="../style.css" rel="stylesheet" type="text/css">
<link href="<c:url value='/admin/assets/style/jqueryform.css'/>" type="text/css" rel="stylesheet" />
<link rel="stylesheet" type="text/css" media="screen" href="<c:url value='/admin/assets/js/jquery/jquery-validate.password/jquery.validate.password.css'/>" />
<script type="text/javascript" src="/admin/assets/js/util.js"></script>
<script type="text/javascript" src="<c:url value='/admin/assets/js/md5.js'/>"></script>
<script type="text/javascript" src="<c:url value='/admin/assets/js/jquery/jquery.js'/>"></script>
<script type="text/javascript" src="<c:url value='/admin/assets/js/jquery/jquery-validate/lib/jquery.metadata.js'/>"></script>
<script type="text/javascript" src="<c:url value='/admin/assets/js/jquery/jquery-validate/jquery.validate.js'/>"></script>
<script type="text/javascript" src="<c:url value='/admin/assets/js/jquery/jquery-validate.password/jquery.validate.password.js'/>"></script>

<script type="text/javascript" language="javascript">
// <![CDATA[
$(document).ready(function() {
	//密码校验
	$.validator.addMethod('passwordValidate', function(value, element, param){
		
		return (hex_md5(value) == "<c:out value='${sessionScope.admin.password}'/>".toLowerCase());
	}, '旧密码不正确请重新输入.');
	
	
	var validator = $("#changePassForm").validate({
		rules: {
			passwordOld: 	        {required: true,	passwordValidate: true},
			password: 		        {required: true,	minlength: 5 , maxlength: 50, password: true},
			password_confirm: 		{required: true,	minlength: 5 , maxlength: 50, equalTo: "#password" }
		},
		messages: {
					passwordOld: {
						required:"请输入旧密码. "
					},
					password: {
						required: "请输入新密码. ",
						minlength:"新密码 最少是 5 个字符",
						maxlength:"新密码 最多是 50 个字符"
					},
					password_confirm: {
						required: "请输入确认密码. ",
						minlength:"确认密码 最少是 5 个字符",
						maxlength:"确认密码 最多是 50 个字符",
						equalTo:"两次输入的密码必须相同"
					}
		},
		// the errorPlacement has to take the table layout into account
		errorPlacement: function(error, element) {
			error.prependTo( element.parent().next() );
		},
		submitHandler:function(form){
            $("#errorTd").html("");
            form.submit();
        },
		// set this class to error-labels to indicate valid fields
		success: function(label) {
			// set &nbsp; as text for IE
			label.html("&nbsp;").addClass("checked");
		}     
	});
	
	
<c:if test="${not empty requestScope.message}">
$("#infoSpan").html("<img src='<c:url value='/admin/assets/images/warning.gif'/>'><font color='#C00000'><c:out value='${requestScope.message}' escapeXml='false'/></font>");
</c:if>

});

// ]]>
</script>

<script language="javascript">
function check()
{
    var oldPwd = document.getElementById("oldPwd");
	var newPwd = document.getElementById("newPwd");
	var newPwd1 = document.getElementById("newPwd1");
	if(oldPwd.value=="")
	{
		OS.showWarming("errorTd","请输入原始密码！");
		oldPwd.focus();
		return false;
	}
	else
	{
		OS.hideWarming("errorTd");
	}
	
	if(newPwd.value=="")
	{
		OS.showWarming("errorTd","请输入新密码！");
		newPwd.focus();
		return false;
	}
	else
	{
		OS.hideWarming("errorTd");
	}
	
	if(newPwd.value!=newPwd1.value)
	{
		OS.showWarming("errorTd","两次密码不一致！");
		newPwd.focus();
		return false;
	}
	else
	{
		OS.hideWarming("errorTd");
	}

	dojo.io.bind({
			url: "admin.ac?method=changePwd",
			formNode:dojo.byId("passwordForm"),
			mimetype:"text/html",
			method:"POST",
			encoding:"UTF-8",
			timeout:10000, 
			preventCache:true,
			load: function(type, data, evt){
				if(data=="success")
				{
					OS.showCue("errorTd","更新成功!");
				}
				else
				{
					OS.showWarming("errorTd","原始密码不正确!")
				}
			},
			error: function(type, error){
				
			},
			timeout: function(type, data, evt){
				
			}
		});
		return false;
}

window.onload = function()
{
	
}

</script>

</head>
<body class="main">
<form method="post" name="changePassForm" id="changePassForm" action="<c:url value='/admin/system/change-password.ac'/>">
<table class="container" cellpadding="0" cellspacing="0">
<tr><td>
<table class="dialog" align="center" cellpadding="0" cellspacing="0" width="700">
<tr><td>
<table class="header" cellpadding="0" cellspacing="0">
<tr>
<td>修改密码</td>
</tr>
</table>
</td></tr>
<tr><td>
<table class="body" cellpadding="0" cellspacing="0">
<tr>
  <td colspan="2" align="center" id="errorTd">&nbsp;<span id="infoSpan" class="infoSpan">&nbsp;</span></td>
  </tr>
<tr>
  <td width="42%" align="right"><strong>原始密码：</strong></td>
  <td width="58%"><input type="password" name="passwordOld" id="passwordOld" size="25" maxlength="20"/><label class="error" for="passwordOld" generated="true" ></label> </td>
</tr>
<tr>
<td align="right"><b>新密码：</b></td>
<td><input type="password" name="password" id="password" size="25" maxlength="20"/>
<label class="error" for="password" generated="true" style="display:none"></label> 
<div class="password-meter">
    <div class="password-meter-message"></div>
    <div class="password-meter-bg">
        <div class="password-meter-bar"></div>
    </div>
</div>
</td>
</tr>
<tr>
<td align="right"><b>确认密码：</b></td>
<td><input type="password" name="password_confirm" id="password_confirm" size="25" maxlength="20"><label class="error" for="password_confirm" generated="true" ></label> </td>
</tr>
<tr>
  <td colspan="2">&nbsp;</td>
  </tr>
</TABLE>
</td></tr>
<tr><td>
<table class="footer" cellpadding="0" cellspacing="0">
<tr><td>
<input class="button" type="submit" value="确定">
&nbsp;&nbsp;<input class="button" type="button" value="返回" onClick="javascript:history.go(-1)">
</td></tr>
</table>
</td></tr>
</table>
</td></tr>
</table>
</form>

</body>
</html>
